/**
 * User: zhangbin
 * Date: 2014/7/29 9:41
 * Function:
 */
import com.bin.in.dao.mysql.MysqlDao;
import com.bin.in.dao.oracle.OracleDao;
import com.bin.in.enitiy.mysql.MysqlEitity;
import com.bin.in.enitiy.oracle.OracleEitity;
import com.bin.in.manager.InfoJpaManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.stereotype.Component;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
		"classpath:applicationContext.xml",
		"classpath:applicationContext-jpa.xml",
		"classpath:applicationContext-jms.xml"
})
public class StartJTAWithJPA {

	@Resource
	private InfoJpaManager manager;

	@Resource
	private OracleDao oracleDao;

	@Resource
	private MysqlDao mysqlDao;

	@Test
	@Rollback(value = false)
	public void test1(){
		manager.createInfo();;
	}

	@Test
	@Transactional
	@Rollback(value = false)
	public void createInfo(){
		OracleEitity oracleEitity = new OracleEitity();
		oracleEitity.setName("用户 oracle");
		oracleEitity.setDes("这个是测试而已");
		OracleEitity oracleEitityR = oracleDao.save(oracleEitity);
		String userid = oracleEitityR.getId();
		OracleEitity eitity = oracleDao.findOne(userid);
		MysqlEitity mysqlEitity = new MysqlEitity();
		mysqlEitity.setName("JTA 下 JPA 的测试");
		mysqlEitity.setDes("whats fuck");
		MysqlEitity mysqlEitityR = mysqlDao.save(mysqlEitity);
	}
}
